

	/**资源对象，包含资源以及资源的引用计数，引用计数为0时，资源会被回收*/
	class ResObject
	{
		public type:number;
		/**引用计数，当引用计数为0时，资源会被释放,如非必要，勿修改此值*/
		private __count:number=0;
		/**资源，如BitmapData，直接调取并不增加应用计数count，不需调用relRes释放，如需增加计数，请调用getRes，释放请调用relRes*/
		public res;
		/**资源加载的路径*/
		public pathKey:string;
		public constructor()
		{
			
		}
		/**获取资源时，请尽量使用getRes，以便引用计数*/
		public getRes():any
		{
			var s = this;
			++s.__count;
			return s.res;
		}
		/**资源释放时，请把引用设置为null，避免重复释放*/
		public relRes():void
		{
			var s = this;
			--s.__count;
			if(s.__count < 0)
				throw(new Error("资源重复释放"));
		}
		public clear(gc:boolean=true):void
		{
			var s = this;
			if(CommonUtil.GYIs(s.res,Laya.Texture))
			{
				if(s.res.bitmapData)
				{
					var url = s.res.bitmapData.source.src;
					if (url.indexOf("blob:") == 0) {
						var winURL = window["URL"] || window["webkitURL"];
						try {
							winURL.revokeObjectURL(url);
						}
						catch (e) {
							console.warn(1037);
						}
					}
				}				
				s.res.bitmap._released = false;
				s.res.destroy(true);
			}			
			s.res = null;
			s.type = 0;
			s.__count = 0;
			ResObject.__pool.push(this);
		}
		/**引用数量*/
		public get count():number
		{
			return this.__count;
		}
		
		private static __pool;
		// private static __s:Single;
		public static getInstance():ResObject
		{			
			if(!ResObject.__pool)
			{
				//_s=new Single;
				ResObject.__pool=[];
			}
			if(ResObject.__pool.length==0)
				return new ResObject();
			return ResObject.__pool.pop();
		}
	}
